<template>
    <!-- 必填 -->
    <div class="ProcessAdvice6">
        <div class="shareHeadClass">
            <p class="colCLas"></p>
            <p class="info">红字确认单确认内容</p>
        </div>
        <el-form
            :model="vmsApprovalHzqrdSimpleVo"
            :rules="rules"
            label-width="140px"
            class="formInline"
            size="small"
            ref="hzqrdspRef"
            :disabled="isLook"
        >
            <el-row>
                <el-col :span="8">
                    <el-form-item label="红字确认单编号：" prop="hzfpxxqrdbh">
                        <el-input
                            :disabled="isDisabledInvoiceInput"
                            v-model="
                                vmsApprovalHzqrdSimpleVo.hzfpxxqrdbh
                            "
                            maxlength="20"
                        ></el-input>
                    </el-form-item>
                </el-col>

                <div style="display: inline-block;" v-if="!isDisabledInvoiceInput">
                    <el-button type="primary" size="small" style="margin-left: 8px" @click="quickAdd">
                        快速添加
                    </el-button>
                    <el-button type="primary" size="small" @click="search">红字信息确认单查询</el-button>
                    <el-button size="small" @click="resize">重置</el-button>
                </div>
            </el-row>

            <el-row>
                <el-col :span="12">
                    <el-form-item
                        label="销方名称："
                        prop="xfmc"
                    >
                        <el-input
                            :disabled="true"
                            v-model="
                                vmsApprovalHzqrdSimpleVo.xsfmc
                            "
                        ></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item
                        label="销方纳税人识别号："
                        prop="xfnsrsbh"
                    >
                        <el-input
                        :disabled="true"
                            
                            v-model="
                                vmsApprovalHzqrdSimpleVo.xsfnsrsbh
                            "
                        ></el-input>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col :span="12">
                    <el-form-item
                        label="购方名称："
                        prop="gfmc"
                    >
                        <el-input
                        :disabled="true"
                            
                            v-model="
                                vmsApprovalHzqrdSimpleVo.gmfmc
                            "
                        ></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item
                        label="购方纳税人识别号："
                        prop="gfnsrsbh"
                    >
                        <el-input
                        :disabled="true"
                            
                            v-model="
                                vmsApprovalHzqrdSimpleVo.gmfnsrsbh
                            "
                        ></el-input>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col :span="8">
                    <el-form-item
                        label="申请方角色："
                        prop="lrfsf"
                    >
                        <el-select
                            v-model="vmsApprovalHzqrdSimpleVo.lrfsf"
                            placeholder="请选择"
                            style="width: 100%"
                            :disabled="true"
                        >
                            <el-option
                                v-for="item in [
                                    { label: '购方', value: '1' },
                                    { label: '销方', value: '0' },
                                ]"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item
                        label="红冲原因："
                        prop="chyy"
                        label-width="100px"

                    >
                        <el-select
                            v-model="
                                vmsApprovalHzqrdSimpleVo.chyydm
                            "
                            :disabled="true"
                            
                            placeholder="请选择"
                            style="width:100%;"
                        >
                            <el-option
                                    v-for="item in [
                                        { label: '开票有误', value: '01' },
                                        { label: '销货退回', value: '02' },
                                        { label: '服务中止', value: '03' },
                                        { label: '销售折让', value: '04' },
                                    ]"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item
                        label="红冲类型："
                        prop="hclx"
                        label-width="100px"

                    >
                        <el-select
                            v-model="
                                vmsApprovalHzqrdSimpleVo.chlx
                            "
                            style="width:100%;"
                            placeholder="请选择"
                            :disabled="true"

                        >
                            <el-option
                                v-for="item in [
                                    {
                                        lxxmc: '全额红冲',
                                        lxxdm: '8'
                                    },
                                    {
                                        lxxmc: '部分红冲',
                                        lxxdm: '7'
                                    },
                                ]"
                                :key="item.lxxdm"
                                :label="item.lxxmc"
                                :value="item.lxxdm"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item
                        label="购买方是否抵扣："
                        prop="gmfsfdk"
                    >
                        <el-select
                            v-model="
                                vmsApprovalHzqrdSimpleVo.gmfsfdkrz
                            "
                            style="width:100%;"
                            :disabled="true"

                            
                            placeholder="请选择"
                        >
                            <el-option
                                v-for="item in [
                                    { label: '是', value: 'Y' },
                                    { label: '否', value: 'N' },
                                ]"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item
                        label="购买方未抵扣原因："
                        prop="gmfwdkyy"
                    >
                       <el-input
                       :disabled="true"
                            v-model="
                                vmsApprovalHzqrdSimpleVo.gmfwdkyy
                            "
                        ></el-input>
                    </el-form-item>
                </el-col>

            </el-row>

                    <el-form-item
                        label="待红冲发票明细："
                    >
                    <tableList
                        border
                        maxHeight="300"
                        :keySet="keySet"
                        :autoHeight="true"
                        :tableData="vmsApprovalHzqrdSimpleVo.vmsApprovalHzqrdItemVoList"
                        handlerFixed="right"
                        
                    >
                        <template #yslbz="{ row }">
                            <div>
                                {{ row.yslbz === 'Y' ? '有原税率' : '无原税率' }}
                            </div>
                        </template>
                        <template #slzsl="{ row }">
                            <div>{{ row.slzsl || 0 }}%</div>
                        </template>
                    </tableList>

                    
                    </el-form-item>

        </el-form>



        <writeOffInvoice v-model="writeOff" :dbRow="dbRow"></writeOffInvoice>

        <searchDialogConfirm v-model="searchDialogShow" v-if="searchDialogShow" :redConfigNumber="vmsApprovalHzqrdSimpleVo.hzfpxxqrdbh" @searchCb="searchCb"></searchDialogConfirm>
    </div>
</template>

<script>
import tableList from '@/components/tableList/index.vue'
import mixinTable from '@/mixin/mtable.js'
import writeOffInvoice from './components/writeOffInvoice.vue'
import searchDialogConfirm from './components/searchDialogConfirm.vue'
import { fastAdd, getConfirmDetail } from '@/api/vmsHzqrdConfirm.js'

export default {
    name: 'redInvoiceConfig9',
    props: {
        invoiceCategory: {
            type: String,
            default: '',
        },
        flag: {
            type: String,
            // default:''
        },
        isLook: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            nodeId:'',
            busStatus:'',
            vmsApprovalHzqrdSimpleVo: {
                "hzfpxxqrdbh": "",
                "xsfnsrsbh": "",
                "sfzzfpSelect": "",
                "gmfmc": "",
                "gmfsfdkrz": "Y",
                "sfzzfpbz": "",
                "chyydm": "01",
                "lzfphm": "",
                "chlxSelect": "",
                "gmfnsrsbh": "",
                "xsfmc": "",
                "lrfsf": "",
                "gmfwdkyy": "",
                "chlx": "",
                vmsApprovalHzqrdItemVoList:[]
            },

            rules: {
                hzfpxxqrdbh: [
                    {
                        required: true,
                        message: '请输入',
                        trigger: 'change',
                    },
                ],

            },

            keySet: [
                {
                    label: '项目名称',
                    englishName: 'hwhyslwfwmc',
                },
                {
                    label: '规格型号',
                    englishName: 'ggxh', //
                },
                {
                    label: '单位',
                    englishName: 'dw', //
                },
                {
                    label: '数量',
                    englishName: 'sl', //
                },
                {
                    label: '单价',
                    englishName: 'dj', //
                },
                {
                    label: '金额',
                    englishName: 'je', //
                },
                {
                    label: '税率',
                    englishName: 'slv', //
                },
                {
                    label: '税额',
                    englishName: 'se', //
                },
                // {
                //     label: '冲销数量',
                //     englishName: 'cxsl', //
                // },
                // {
                //     label: '冲销金额',
                //     englishName: 'cxje', //
                // },
                // {
                //     label: '冲销税额',
                //     englishName: 'cxse', //
                // },
            ],

            writeOff:false,
            searchDialogShow:false,

            dbRow:null,

        }
    },
    created() {
        this.getDetail()
    },
    methods: {
        getDetail(){
            let obj = JSON.parse(
                sessionStorage.getItem('handleDetailInfo')
            )
            this.nodeId = obj.nodeId
            this.busStatus = obj.busStatus
            if(obj.busId){ // 判断是否是详情页
                getConfirmDetail( obj.busId ).then(({data,code})=>{
                    if(code ==200){
                        this.vmsApprovalHzqrdSimpleVo = {
                            ...this.vmsApprovalHzqrdSimpleVo,
                            ...data.vmsApprovalHzqrdSimpleVo,
                            vmsApprovalHzqrdItemVoList:data.vmsApprovalHzqrdItemVoList
                        };
                    }
                })
            }
        },  
        quickAdd(){ 
            let params = new URLSearchParams('');
            params.append("hzxxqrdbh", this.vmsApprovalHzqrdSimpleVo.hzfpxxqrdbh);
            params.append("applyId", this.$store.state.invoice2.invoinceFormStart1.busId);

            fastAdd(params).then(({data,code})=>{

            // fastAdd(this.vmsApprovalHzqrdSimpleVo.hzfpxxqrdbh).then(({data,code})=>{
                if(code ==200){
                    this.vmsApprovalHzqrdSimpleVo = {
                        ...this.vmsApprovalHzqrdSimpleVo,
                        ...data.vmsApprovalHzqrdSimpleVo,
                        vmsApprovalHzqrdItemVoList: data.vmsApprovalHzqrdItemVoList
                    };

                }
            })
        },
        searchCb(obj){
            this.searchDialogShow = obj.show;
            console.log(obj);
            if(obj.row&&obj.row.hzfpxxqrdbh){
                this.vmsApprovalHzqrdSimpleVo.hzfpxxqrdbh = obj.row.hzfpxxqrdbh;
                this.quickAdd()
            }
        },
        search(){
            this.searchDialogShow = true
        },
        resize(){
            this.vmsApprovalHzqrdSimpleVo.hzfpxxqrdbh = ''
        },
    },
    computed:{
        isDisabledInvoiceInput(){
            // || this.busStatus != '3'
            // let res = (this.nodeId == '' || this.nodeId == 'root' );
            // console.log(res);
            return false
        }
    },
    mixins: [mixinTable],
    components: {
        tableList,
        writeOffInvoice,
        searchDialogConfirm,
    },
}
</script>

<style lang = "scss" scoped>
    ::v-deep .vxe-modal--wrapper  .vxe-modal--content{
        white-space: none;
    }
</style>
